home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / os2 / gnuwget.zip / wget-1.4.3 / src / url.h < prev    next >
C/C++ Source or Header  |  1997-01-30  |  6KB  |  146 lines

  1. /* Declarations for URL handling.
  2.    Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
  3.    
  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 2 of the License, or
  7.    (at your option) any later version.
  8.    
  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.
  13.    
  14.    You should have received a copy of the GNU General Public License
  15.    along with this program; if not, write to the Free Software
  16.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18.  
  19. #ifndef URL_H
  20. #define URL_H
  21.  
  22. /* URL separator (for findurl) */
  23. #define URL_SEPARATOR "!\"#'(),>`{}|<>"
  24.  
  25. /* Default port definitions */
  26. #define DEFAULT_HTTP_PORT 80
  27. #define DEFAULT_FTP_PORT 21
  28.  
  29. /* Tha smaller value of the two. */
  30. #define MINVAL(x, y) ((x) < (y) ? (x) : (y))
  31.  
  32. /* ASCII char -> HEX digit */
  33. #define ASC2HEXD(x) (((x) >= '0' && (x) <= '9') ?               \
  34.              ((x) - '0') : (toupper(x) - 'A' + 10))
  35.  
  36. /* HEX digit -> ASCII char */
  37. #define HEXD2ASC(x) (((x) >= 0 && (x) <= 9) ?           \
  38.              ((x) + '0') : ((x) - 10 + 'A'))
  39.  
  40. /* A list of unsafe characters for encoding, as per RFC1738.  '@' and
  41.    ':' (not listed in RFC) were added because of user/password
  42.    encoding, and \033 because of safe printing. */
  43. #define URL_UNSAFE " <>\"#%{}|\\^~[]`@:\033"
  44.  
  45. /* If the string contains unsafe characters, duplicate it with
  46.    encode_string, otherwise just copy it with strdup. */
  47. #define CLEANDUP(x) (contains_unsafe(x) ? encode_string(x) : nstrdup(x))
  48.  
  49. /* Just another ugly macro (defines a static local char *). */
  50. #define URL_CLEANSE(s)                                          \
  51.    do { if (contains_unsafe(s)) { static char *tmp;             \
  52.    tmp = encode_string(s); free(s); s = tmp; }} while (0);
  53.  
  54. /* Is a directory "."? */
  55. #define ISDOT(x) ((*(x) == '.') && (!*(x + 1)))
  56. /* Is a directory ".."? */
  57. #define ISDDOT(x) ((*(x) == '.') && (*(x + 1) == '.') && (!*(x + 2)))
  58.  
  59. #define USE_PROXY(u) (opt.use_proxy && getproxy((u)->proto)             \
  60.                       && no_proxy_match((u)->host,                      \
  61.                                         (const char **)opt.no_proxy))
  62.  
  63. /* Structure containing info on a protocol. */
  64. typedef struct proto {
  65.    char *name;
  66.    uerr_t ind;
  67.    unsigned short port;
  68. } proto_t;
  69.  
  70. /* Structure containing info on a URL. */
  71. typedef struct _urlinfo {
  72.    char *url;                   /* Unchanged URL */
  73.    uerr_t proto;                /* URL protocol */
  74.    char *host;                  /* Extracted hostname */
  75.    unsigned short port;
  76.    char *path, *dir, *file;     /* Path, as well as dir and file
  77.                                    (properly decoded) */
  78.    char *user, *passwd;         /* For FTP */
  79.    struct _urlinfo *proxy;      /* The exact string to pass to proxy
  80.                                    server. */
  81.    char *referer;               /* The source from which the request
  82.                                    URI was obtained. */
  83.    char *local;                 /* The local filename of the URL
  84.                                    document. */
  85. } urlinfo;
  86.  
  87. enum uflags {
  88.    URELATIVE     = 0x0001,      /* Is URL relative? */
  89.    UNOPROTO      = 0x0002,      /* Is URL without a protocol? */
  90.    UABS2REL      = 0x0004,      /* Convert absolute to relative? */
  91.    UREL2ABS      = 0x0008       /* Convert relative to absolute? */
  92. };
  93.  
  94. /* A structure that defines the whereabouts of a URL, i.e. its
  95.    position in an HTML document, etc. */
  96. typedef struct _urlpos {
  97.    char *url;                   /* URL */
  98.    char *local_name;            /* Local file to which it was saved. */
  99.    enum uflags flags;           /* Various flags. */
  100.    int pos, size;               /* Rekative position in the buffer. */
  101.    struct _urlpos *next;        /* Next struct in list. */
  102. } urlpos;
  103.  
  104.  
  105. /* Function declarations */
  106.  
  107. int skip_url PARAMS((const char *));
  108.  
  109. int contains_unsafe PARAMS((const char *));
  110. void decode_string PARAMS((char *));
  111. char *encode_string PARAMS((const char *));
  112.  
  113. urlinfo *newurl PARAMS((void));
  114. void freeurl PARAMS((urlinfo *, int));
  115. uerr_t urlproto PARAMS((const char *));
  116. int skip_proto PARAMS((const char *));
  117. int has_proto PARAMS((const char *));
  118. int skip_uname PARAMS((const char *));
  119.  
  120. uerr_t parseurl PARAMS((const char *, urlinfo *, int));
  121. uerr_t parse_uname PARAMS((const char *, char **, char **));
  122. void parse_dir PARAMS((const char *, char **, char **));
  123. char *str_url PARAMS((const urlinfo *, int));
  124. int url_equal PARAMS((const char *, const char *));
  125.  
  126. const char *findurl PARAMS((const char *, int, int *));
  127. urlpos *get_urls_file PARAMS((const char *));
  128. urlpos *get_urls_html PARAMS((const char *, const char *, int));
  129. void free_urlpos PARAMS((urlpos *));
  130.  
  131. int mkalldirs PARAMS((const char *));
  132. char *mkstruct PARAMS((const urlinfo *));
  133. char *url_filename PARAMS((const urlinfo *));
  134. char *unique_name PARAMS((const char *, int));
  135. char *construct PARAMS((const char *, const char *, int, int));
  136. void opt_url PARAMS((urlinfo *));
  137.  
  138. char *getproxy PARAMS((uerr_t));
  139. int no_proxy_match PARAMS((const char *, const char **));
  140.  
  141. void convert_links PARAMS((const char *, urlpos *));
  142. char *construct_relative PARAMS((const char *, const char *));
  143. urlpos *add_url PARAMS((urlpos *, const char *, const char *));
  144.  
  145. #endif /* URL_H */
  146.